package cn.wegoteam.shop.adm.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import cn.wegoteam.shop.action.BaseAction;
import cn.wegoteam.shop.inter.OrderServiceInter;
import cn.wegoteam.shop.po.Order;

@ParentPackage("manage")
@Namespace("/")
@Controller
public class ManOrderAction extends BaseAction<Order>{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7214652284224332303L;
	@Autowired
	private OrderServiceInter orderService;

	@Action(value = "manageOrderList", results = { @Result(name = SUCCESS, location = MANAGE
			+ "list.jsp") })
	public String manageOrderList() {
		return SUCCESS;
	}

	@Action(value = "manageLoadOrderList")
	public void loadOrderList() {
		int pageSize = getIntParameter("pagesize");
		int currentPage = getIntParameter("page");
		pageBean.setSize(pageSize == 0 ? defaultSize : pageSize);
		pageBean.setCurrentPage(currentPage == 0 ? 1 : currentPage);
		pageBean.setTotalPage(getIntParameter("totalPage"));
		writeStringToResponse(orderService.getJsonList(pageBean,null,null,request));
	}

	@Action(value = "manageFindOrderById", results = { @Result(name = SUCCESS, location = MANAGE
			+ "addOrder.jsp") })
	public String findOrderById() {
		if (model.getId() != null)
			model = orderService.get(model.getId());
		return SUCCESS;
	}

	@Action(value = "manageAddOrder")
	public String addOrder() {
		if(model.getId()==null)
			orderService.saveOrUpdate(model);
		else
			orderService.updateBySql(model);
		return OPTRESULTSUCCESS;
	}

	@Action(value = "manageDeleteOrder")
	public void deleteOrder() {
		writeStringToResponse(orderService.delete(model));
	}

	/****************************************************** get() and set() ***********************************/


}
